package org.springblade.modules.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.admin.entity.MaintainCompany;
import org.springblade.modules.admin.service.MaintainCompanyService;
import org.springblade.modules.admin.vo.MaintainCompanyVO;
import org.springblade.modules.admin.wrapper.MaintainCompanyWrapper;
import org.springblade.modules.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Date: 2020/12/28 11:27 上午
 * @Author: Jackey
 * @Description: 维保公司
 */
@RestController
@RequestMapping("/admin/maintain_company")
public class MaintainCompanyController {

	@Autowired
	private MaintainCompanyService maintainCompanyService;
	@Autowired
	private IUserService userService;

	/**
	 * 新增 维保公司
	 */
	@PostMapping()
	public R<Boolean> save(@Valid @RequestBody MaintainCompany maintainCompany) {
		return R.status(maintainCompanyService.save(maintainCompany));
	}

	/**
	 * 详情
	 */
	@GetMapping("/{id}")
	public R<MaintainCompanyVO> detail(@PathVariable Long id) {
		MaintainCompany detail = maintainCompanyService.getById(id);
		return R.data(MaintainCompanyWrapper.build().entityVO(detail));
	}

	/**
	 * 分页
	 */
	@GetMapping("")
	public R<IPage<MaintainCompanyVO>> list(MaintainCompany maintainCompany, Query query) {
		IPage<MaintainCompanyVO> pages = maintainCompanyService.selectPages(Condition.getPage(query),maintainCompany);

		return R.data(pages);
	}

	/**
	 * 修改
	 */
	@PutMapping("/{id}")
	public R<Boolean> update(@PathVariable Long id, @Valid @RequestBody MaintainCompany maintainCompany) {
		maintainCompany.setId(id);
		return R.status(maintainCompanyService.updateById(maintainCompany));
	}

	/**
	 * 删除
	 */
	@DeleteMapping()
	public R<Boolean> remove(@RequestParam String ids) {
		return R.status(maintainCompanyService.removeById(Func.toLong(ids)));
	}


	/**
	 * 公司所有维保人员列表
	 * @return
	 */
	@GetMapping("/list")
	public R<List<MaintainCompanyVO>> list() {
		List<MaintainCompanyVO> maintainCompanyVOList = maintainCompanyService.maintainCompanyVOList();
		return R.data(maintainCompanyVOList);
	}


}
